package com.test.mchelepesa.dialog_rice;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.os.Bundle;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.test.mchelepesa.R;
import com.test.mchelepesa.activity_fragment_rice.base_rice.BaseActivity_rice;
import com.test.mchelepesa.util_rice.StringUtil_rice;
import com.test.mchelepesa.util_rice.ThreadUtil_rice;

public class MsgDialog extends Dialog {

    private final String text;
    private final Runnable onClickListener;

    public MsgDialog(@NonNull BaseActivity_rice activity,String text,Runnable onClickListener) {
        super(activity);
        this.text = text;
        this.onClickListener = onClickListener;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_msg);
        getWindow().setBackgroundDrawableResource(R.color.trans);
        setCanceledOnTouchOutside(false);
        initView();
    }

    @SuppressLint({"SetTextI18n", "ResourceAsColor"})
    private void initView(){

        TextView textTv = findViewById(R.id.dialog_msg_tv_text);

        textTv.setText(StringUtil_rice.getSafeString(text));

        ThreadUtil_rice.getInstance().postDelay(() -> {
            if (isShowing()) {
                dismiss();
                if (onClickListener!=null) onClickListener.run();
            }
        },3000);
    }

}
